package com.ithome.controller;

import com.ithome.mapper.UserMapper;
import com.ithome.pojo.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.HashMap;
import java.util.List;

/**
 * @author sandu
 * @create 2020-06-12 13:56
 */
@RestController
@RequestMapping("/login")
public class UserController {

	@Autowired
	private UserMapper userMapper;


	@PostMapping("/login")
	public String login(HttpServletRequest request, HttpServletResponse response,  Model model){
		String loginName = request.getParameter("txtEmail");
		String loginPasswd = request.getParameter("txtPwd");

		HashMap<String, Object> map = new HashMap<>();
		map.put("uName",loginName);
		map.put("uPassword",loginPasswd);
		List<User> user = userMapper.selectByMap(map);

		if (user!=null){
			model.addAttribute("login-msg","登录成功");
		}else {
			model.addAttribute("login-msg","请先注册");
		}


		return null;

	}
}
